<?php
/**
 * Simple PHP Contact Form
 *
 * This file is part of the Simple PHP Contact Form which is subject to the New
 * BSD License {@see LICENSE} which you would be advised to read before using,
 * modifying or redistributing this software.
 *
 * PHP version 5.2
 *
 * @category  Simple-PHP-Contact-Form
 * @package   Application
 * @author    jah <jah@jahboite.co.uk>
 * @copyright 2010 jah <jah@jahboite.co.uk>
 * @license   New BSD License {@see LICENSE}
 * @version   SVN: $Id$
 * @link      http://code.google.com/p/simple-php-contact-form/
 */


/*
 *  Define constants for some special characters {}|&~![]()^" which may be used
 *  for character set specifications in the congiguration ini files.
 */
defined('EXCLAMATION_MARK')     || define('EXCLAMATION_MARK', chr(0x21));
defined('QUOTATION_MARK')       || define('QUOTATION_MARK', chr(0x22));
defined('AMPERSAND')            || define('AMPERSAND', chr(0x26));
defined('LEFT_PARENTHESIS')     || define('LEFT_PARENTHESIS', chr(0x28));
defined('RIGHT_PARENTHESIS')    || define('RIGHT_PARENTHESIS', chr(0x29));
defined('LEFT_SQUARE_BRACKET')  || define('LEFT_SQUARE_BRACKET', chr(0x5B));
defined('RIGHT_SQUARE_BRACKET') || define('RIGHT_SQUARE_BRACKET', chr(0x5D));
defined('CIRCUMFLEX_ACCENT')    || define('CIRCUMFLEX_ACCENT', chr(0x5E));
defined('LEFT_CURLY_BRACKET')   || define('LEFT_CURLY_BRACKET', chr(0x7B));
defined('VERTICAL_LINE')        || define('VERTICAL_LINE', chr(0x7C));
defined('RIGHT_CURLY_BRACKET')  || define('RIGHT_CURLY_BRACKET', chr(0x7D));
defined('TILDE')                || define('TILDE', chr(0x7E));


/**
 * Bootstrap.  The Front Controller page public/index.php calls the methods in this
 * file in order to 'bootstrap' the application.
 *
 * @category  Simple-PHP-Contact-Form
 * @package   Application
 * @author    jah <jah@jahboite.co.uk>
 * @copyright 2010 jah <jah@jahboite.co.uk>
 * @license   New BSD License {@see LICENSE}
 * @version   Release: @package_version@
 * @link      http://code.google.com/p/simple-php-contact-form/
 */

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    /**
     * Initialises the Zend_Application_Module_Autoloader.
     *
     * @return Zend_Application_Module_Autoloader An autoloader as a bootsrap
     *                                            resource.
     */
    protected function _initAutoload()
    {
        $autoloader = new Zend_Application_Module_Autoloader(
            array(
                'namespace' => '',
                'basePath'  => dirname(__FILE__),
            )
        );
        return $autoloader;
    }


    /**
     * Creates a response object, sets the Content-Type header and assigns the
     * response to the front controller.
     *
     * @return null
     */
    protected function _initResponseCharset()
    {
        $front = Zend_Controller_Front::getInstance();
        $response = new Zend_Controller_Response_Http;
        $response->setHeader('Content-Type', 'text/html; charset=utf-8', false);
        $front->setResponse($response);
    }


    /**
     * Register Action Helpers with the helper broker.
     *
     * @return null
     */
    protected function _initAppHelpers()
    {
        // Register a directory:class prefix mapping.
        Zend_Controller_Action_HelperBroker::addPath(
            APPLICATION_PATH . '/controllers/helpers',
            'App_Helper'
        );
    }


    /**
     * Add a Custom namepsace to the loader so that it autoloads custom classes.
     *
     * @return null
     */
    protected function _initCustomNamespace()
    {
        $autoloader = Zend_Loader_Autoloader::getInstance();
        $autoloader->registerNamespace('Custom_');
    }


    /**
     * Modify Routing.  Instead of the default routing this application will
     * accept a recipient name in place of the action method in the url.
     * For example: http://somesite.com/contact/Obi-Wan.Kenobi will route to the
     * default module > index controller > index action method with a recipient
     * parameter to which the recipient name is assigned.  The index controller
     * handles the decision as to whether the url contains an action method,
     * a valid recipient or something else.
     *
     * @return null
     */
    protected function _initRouter()
    {
        $controller = Zend_Controller_Front::getInstance();
        $router = $controller->getRouter();

        $routes = array(
            'default' => new Zend_Controller_Router_Route(
                '/:action',
                array(
                    'controller' => 'index',
                    'action'     => 'index',
                    'module'     => 'default',
                )
            )
        );

        $router->addRoutes($routes);
    }


}
